package com.example.demo.utils;

import com.example.demo.User;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;

public class JsonUtil {
    public static void main(String[] args) throws JsonProcessingException {
        //这只是其中的一个方法，这其中互相转化的方式有很多种
        User user = new User();
        //json的转换工具
        ObjectMapper objectMapper = new ObjectMapper();
        String str=objectMapper.writeValueAsString(user);
        System.out.println(str);

        User user1 = objectMapper.readValue(str, User.class);
        System.out.println(user1);
    }
}
